package com.mq.exchange;

import com.mq.ConnectionUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

public class SendExchange {

    private static final String EXCHANGE_NAME = "test_exchange_fanout";

    public static void main(String args[]) throws Exception {
        //获取连接
        Connection connection = ConnectionUtils.getConnection();

        //获取channel
        Channel channel = connection.createChannel();

        //声明交换机
        channel.exchangeDeclare(EXCHANGE_NAME,"fanout");  //分发

        //发送消息
        String msg = "hello p/s";
        channel.basicPublish(EXCHANGE_NAME,"",null,msg.getBytes());
        System.out.println("Send " + msg);

        //关闭
        channel.close();
        connection.close();
    }
}